//
// Created by Tony on 2024/7/28.
//

#include "NEW.h"
#include "../rt_code/Class.h"
#include <memory>

namespace Runtime {

void NEW::execute(RtData::Frame& frame) {
    auto& curMethod = frame.getMethod();
    shared_ptr<RtCode::Class> curClass = curMethod->getOwnerClass();
    auto& curConstPool = curClass->getConstantPool();
    auto* classRef = curConstPool.getClassRef(mIndex);
    auto clazz = classRef->resolvedClass();

    if (!clazz->isInitStarted()) {
        initClass(frame, clazz);
        return;
    }

    auto* obj = clazz->newObject();
    frame.pushRef(obj);
}

} // namespace Runtime
